.class public LPlugclass/ImageFileCache;
.super Ljava/lang/Object;
.source "ImageFileCache.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        LPlugclass/ImageFileCache$FileLastModifSort;
    }
.end annotation


# static fields
.field private static final CACHDIR:Ljava/lang/String; = "ImgCach"

.field private static final CACHE_SIZE:I = 0xa

.field private static final FREE_SD_SPACE_NEEDED_TO_CACHE:I = 0xa

.field private static final MB:I = 0x100000

.field private static final WHOLESALE_CONV:Ljava/lang/String; = ".cach"


# direct methods
.method public constructor <init>()V
    .locals 1

    .prologue
    .line 25
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 27
    invoke-direct {p0}, LPlugclass/ImageFileCache;->getDirectory()Ljava/lang/String;

    move-result-object v0

    invoke-direct {p0, v0}, LPlugclass/ImageFileCache;->removeCache(Ljava/lang/String;)Z

    .line 28
    return-void
.end method

.method private convertUrlToFileName(Ljava/lang/String;)Ljava/lang/String;
    .locals 3
    .param p1, "url"    # Ljava/lang/String;

    .prologue
    .line 131
    const-string v1, "/"

    invoke-virtual {p1, v1}, Ljava/lang/String;->split(Ljava/lang/String;)[Ljava/lang/String;

    move-result-object v0

    .line 132
    .local v0, "strs":[Ljava/lang/String;
    new-instance v1, Ljava/lang/StringBuilder;

    array-length v2, v0

    add-int/lit8 v2, v2, -0x1

    aget-object v2, v0, v2

    invoke-static {v2}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v2

    invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v2, ".cach"

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v1

    return-object v1
.end method

.method private freeSpaceOnSd()I
    .locals 7

    .prologue
    .line 124
    new-instance v2, Landroid/os/StatFs;

    invoke-static {}, Landroid/os/Environment;->getExternalStorageDirectory()Ljava/io/File;

    move-result-object v3

    invoke-virtual {v3}, Ljava/io/File;->getPath()Ljava/lang/String;

    move-result-object v3

    invoke-direct {v2, v3}, Landroid/os/StatFs;-><init>(Ljava/lang/String;)V

    .line 125
    .local v2, "stat":Landroid/os/StatFs;
    invoke-virtual {v2}, Landroid/os/StatFs;->getAvailableBlocks()I

    move-result v3

    int-to-double v3, v3

    invoke-virtual {v2}, Landroid/os/StatFs;->getBlockSize()I

    move-result v5

    int-to-double v5, v5

    mul-double/2addr v3, v5

    const-wide/high16 v5, 0x4130000000000000L    # 1048576.0

    div-double v0, v3, v5

    .line 126
    .local v0, "sdFreeMB":D
    double-to-int v3, v0

    return v3
.end method

.method private getDirectory()Ljava/lang/String;
    .locals 3

    .prologue
    .line 137
    new-instance v1, Ljava/lang/StringBuilder;

    invoke-direct {p0}, LPlugclass/ImageFileCache;->getSDPath()Ljava/lang/String;

    move-result-object v2

    invoke-static {v2}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v2

    invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v2, "/"

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    const-string v2, "ImgCach"

    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v0

    .line 138
    .local v0, "dir":Ljava/lang/String;
    return-object v0
.end method

.method private getSDPath()Ljava/lang/String;
    .locals 4

    .prologue
    .line 143
    const/4 v1, 0x0

    .line 144
    .local v1, "sdDir":Ljava/io/File;
    invoke-static {}, Landroid/os/Environment;->getExternalStorageState()Ljava/lang/String;

    move-result-object v2

    .line 145
    const-string v3, "mounted"

    .line 144
    invoke-virtual {v2, v3}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v0

    .line 146
    .local v0, "sdCardExist":Z
    if-eqz v0, :cond_0

    .line 147
    invoke-static {}, Landroid/os/Environment;->getExternalStorageDirectory()Ljava/io/File;

    move-result-object v1

    .line 149
    :cond_0
    if-eqz v1, :cond_1

    .line 150
    invoke-virtual {v1}, Ljava/io/File;->toString()Ljava/lang/String;

    move-result-object v2

    .line 152
    :goto_0
    return-object v2

    :cond_1
    const-string v2, ""

    goto :goto_0
.end method

.method private removeCache(Ljava/lang/String;)Z
    .locals 12
    .param p1, "dirPath"    # Ljava/lang/String;

    .prologue
    const/16 v11, 0xa

    const/4 v5, 0x1

    const/4 v6, 0x0

    .line 81
    new-instance v0, Ljava/io/File;

    invoke-direct {v0, p1}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    .line 82
    .local v0, "dir":Ljava/io/File;
    invoke-virtual {v0}, Ljava/io/File;->listFiles()[Ljava/io/File;

    move-result-object v2

    .line 83
    .local v2, "files":[Ljava/io/File;
    if-nez v2, :cond_1

    .line 112
    :cond_0
    :goto_0
    return v5

    .line 86
    :cond_1
    invoke-static {}, Landroid/os/Environment;->getExternalStorageState()Ljava/lang/String;

    move-result-object v7

    .line 87
    const-string v8, "mounted"

    .line 86
    invoke-virtual {v7, v8}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v7

    .line 87
    if-nez v7, :cond_2

    move v5, v6

    .line 88
    goto :goto_0

    .line 91
    :cond_2
    const/4 v1, 0x0

    .line 92
    .local v1, "dirSize":I
    const/4 v3, 0x0

    .local v3, "i":I
    :goto_1
    array-length v7, v2

    if-lt v3, v7, :cond_5

    .line 98
    const/high16 v7, 0xa00000

    if-gt v1, v7, :cond_3

    invoke-direct {p0}, LPlugclass/ImageFileCache;->freeSpaceOnSd()I

    move-result v7

    if-le v11, v7, :cond_4

    .line 99
    :cond_3
    const-wide v7, 0x3fd999999999999aL    # 0.4

    array-length v9, v2

    int-to-double v9, v9

    mul-double/2addr v7, v9

    const-wide/high16 v9, 0x3ff0000000000000L    # 1.0

    add-double/2addr v7, v9

    double-to-int v4, v7

    .line 100
    .local v4, "removeFactor":I
    new-instance v7, LPlugclass/ImageFileCache$FileLastModifSort;

    const/4 v8, 0x0

    invoke-direct {v7, p0, v8}, LPlugclass/ImageFileCache$FileLastModifSort;-><init>(LPlugclass/ImageFileCache;LPlugclass/ImageFileCache$FileLastModifSort;)V

    invoke-static {v2, v7}, Ljava/util/Arrays;->sort([Ljava/lang/Object;Ljava/util/Comparator;)V

    .line 101
    const/4 v3, 0x0

    :goto_2
    if-lt v3, v4, :cond_7

    .line 108
    .end local v4    # "removeFactor":I
    :cond_4
    invoke-direct {p0}, LPlugclass/ImageFileCache;->freeSpaceOnSd()I

    move-result v7

    if-gt v7, v11, :cond_0

    move v5, v6

    .line 109
    goto :goto_0

    .line 93
    :cond_5
    aget-object v7, v2, v3

    invoke-virtual {v7}, Ljava/io/File;->getName()Ljava/lang/String;

    move-result-object v7

    const-string v8, ".cach"

    invoke-virtual {v7, v8}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z

    move-result v7

    if-eqz v7, :cond_6

    .line 94
    int-to-long v7, v1

    aget-object v9, v2, v3

    invoke-virtual {v9}, Ljava/io/File;->length()J

    move-result-wide v9

    add-long/2addr v7, v9

    long-to-int v1, v7

    .line 92
    :cond_6
    add-int/lit8 v3, v3, 0x1

    goto :goto_1

    .line 102
    .restart local v4    # "removeFactor":I
    :cond_7
    aget-object v7, v2, v3

    invoke-virtual {v7}, Ljava/io/File;->getName()Ljava/lang/String;

    move-result-object v7

    const-string v8, ".cach"

    invoke-virtual {v7, v8}, Ljava/lang/String;->contains(Ljava/lang/CharSequence;)Z

    move-result v7

    if-eqz v7, :cond_8

    .line 103
    aget-object v7, v2, v3

    invoke-virtual {v7}, Ljava/io/File;->delete()Z

    .line 101
    :cond_8
    add-int/lit8 v3, v3, 0x1

    goto :goto_2
.end method


# virtual methods
.method public getImage(Ljava/lang/String;)Landroid/graphics/Bitmap;
    .locals 5
    .param p1, "url"    # Ljava/lang/String;

    .prologue
    .line 32
    new-instance v3, Ljava/lang/StringBuilder;

    invoke-direct {p0}, LPlugclass/ImageFileCache;->getDirectory()Ljava/lang/String;

    move-result-object v4

    invoke-static {v4}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v4

    invoke-direct {v3, v4}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v4, "/"

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-direct {p0, p1}, LPlugclass/ImageFileCache;->convertUrlToFileName(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v3, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v3

    invoke-virtual {v3}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    .line 33
    .local v2, "path":Ljava/lang/String;
    new-instance v1, Ljava/io/File;

    invoke-direct {v1, v2}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    .line 34
    .local v1, "file":Ljava/io/File;
    invoke-virtual {v1}, Ljava/io/File;->exists()Z

    move-result v3

    if-eqz v3, :cond_0

    .line 35
    invoke-static {v2}, Landroid/graphics/BitmapFactory;->decodeFile(Ljava/lang/String;)Landroid/graphics/Bitmap;

    move-result-object v0

    .line 36
    .local v0, "bmp":Landroid/graphics/Bitmap;
    if-nez v0, :cond_1

    .line 37
    invoke-virtual {v1}, Ljava/io/File;->delete()Z

    .line 43
    .end local v0    # "bmp":Landroid/graphics/Bitmap;
    :cond_0
    const/4 v0, 0x0

    :goto_0
    return-object v0

    .line 39
    .restart local v0    # "bmp":Landroid/graphics/Bitmap;
    :cond_1
    invoke-virtual {p0, v2}, LPlugclass/ImageFileCache;->updateFileTime(Ljava/lang/String;)V

    goto :goto_0
.end method

.method public saveBitmap(Landroid/graphics/Bitmap;Ljava/lang/String;)V
    .locals 8
    .param p1, "bm"    # Landroid/graphics/Bitmap;
    .param p2, "url"    # Ljava/lang/String;

    .prologue
    .line 48
    if-nez p1, :cond_1

    .line 73
    :cond_0
    :goto_0
    return-void

    .line 52
    :cond_1
    const/16 v6, 0xa

    invoke-direct {p0}, LPlugclass/ImageFileCache;->freeSpaceOnSd()I

    move-result v7

    if-gt v6, v7, :cond_0

    .line 56
    invoke-direct {p0, p2}, LPlugclass/ImageFileCache;->convertUrlToFileName(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v4

    .line 57
    .local v4, "filename":Ljava/lang/String;
    invoke-direct {p0}, LPlugclass/ImageFileCache;->getDirectory()Ljava/lang/String;

    move-result-object v0

    .line 58
    .local v0, "dir":Ljava/lang/String;
    new-instance v1, Ljava/io/File;

    invoke-direct {v1, v0}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    .line 59
    .local v1, "dirFile":Ljava/io/File;
    invoke-virtual {v1}, Ljava/io/File;->exists()Z

    move-result v6

    if-nez v6, :cond_2

    .line 60
    invoke-virtual {v1}, Ljava/io/File;->mkdirs()Z

    .line 61
    :cond_2
    new-instance v3, Ljava/io/File;

    new-instance v6, Ljava/lang/StringBuilder;

    invoke-static {v0}, Ljava/lang/String;->valueOf(Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v7

    invoke-direct {v6, v7}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    const-string v7, "/"

    invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6, v4}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v6

    invoke-direct {v3, v6}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    .line 63
    .local v3, "file":Ljava/io/File;
    :try_start_0
    invoke-virtual {v3}, Ljava/io/File;->createNewFile()Z

    .line 64
    new-instance v5, Ljava/io/FileOutputStream;

    invoke-direct {v5, v3}, Ljava/io/FileOutputStream;-><init>(Ljava/io/File;)V

    .line 65
    .local v5, "outStream":Ljava/io/OutputStream;
    sget-object v6, Landroid/graphics/Bitmap$CompressFormat;->JPEG:Landroid/graphics/Bitmap$CompressFormat;

    const/16 v7, 0x64

    invoke-virtual {p1, v6, v7, v5}, Landroid/graphics/Bitmap;->compress(Landroid/graphics/Bitmap$CompressFormat;ILjava/io/OutputStream;)Z

    .line 66
    invoke-virtual {v5}, Ljava/io/OutputStream;->flush()V

    .line 67
    invoke-virtual {v5}, Ljava/io/OutputStream;->close()V
    :try_end_0
    .catch Ljava/io/FileNotFoundException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_1

    goto :goto_0

    .line 68
    .end local v5    # "outStream":Ljava/io/OutputStream;
    :catch_0
    move-exception v2

    .line 69
    .local v2, "e":Ljava/io/FileNotFoundException;
    const-string v6, "ImageFileCache"

    const-string v7, "FileNotFoundException"

    invoke-static {v6, v7}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_0

    .line 70
    .end local v2    # "e":Ljava/io/FileNotFoundException;
    :catch_1
    move-exception v2

    .line 71
    .local v2, "e":Ljava/io/IOException;
    const-string v6, "ImageFileCache"

    const-string v7, "IOException"

    invoke-static {v6, v7}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;)I

    goto :goto_0
.end method

.method public updateFileTime(Ljava/lang/String;)V
    .locals 3
    .param p1, "path"    # Ljava/lang/String;

    .prologue
    .line 117
    new-instance v0, Ljava/io/File;

    invoke-direct {v0, p1}, Ljava/io/File;-><init>(Ljava/lang/String;)V

    .line 118
    .local v0, "file":Ljava/io/File;
    invoke-static {}, Ljava/lang/System;->currentTimeMillis()J

    move-result-wide v1

    .line 119
    .local v1, "newModifiedTime":J
    invoke-virtual {v0, v1, v2}, Ljava/io/File;->setLastModified(J)Z

    .line 120
    return-void
.end method
